<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title></title>
    <link rel="stylesheet" href="{$Assets}layui/css/layui.css">
    <style type="text/css">
        .layui-input-block{
            margin-right: 50px;   
        }
    </style>
</head>
<body>

<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>添加商品</legend>
</fieldset>

<form class="layui-form" action="">


  <div class="layui-form-item">
    <label class="layui-form-label">标题</label>
    <div class="layui-input-block">
      <input type="text" name="title" lay-verify="required" autocomplete="off" placeholder="" class="layui-input">
    </div>
  </div>

  <div class="layui-form-item">
    <label class="layui-form-label">库存</label>
    <div class="layui-input-inline">
      <input type="text" name="num" lay-verify="required|number" placeholder="" autocomplete="off" class="layui-input">
    </div>
  </div>


  <div class="layui-form-item">
    <label class="layui-form-label">积分</label>
    <div class="layui-input-inline">
      <input type="text" name="pay" lay-verify="required|number" placeholder="" autocomplete="off" class="layui-input">
    </div>
  </div>
  <div class="layui-form-item">
    <div class="layui-upload">
      <button type="button" class="layui-btn" id="test1" style="margin-left: 46px;float: left;">封面</button>
      <div class="layui-upload-list" style="float: left;height: 80px;margin:0px;">
        <img class="layui-upload-img" id="demo1" style="height: 80px;">
        <p id="demoText"></p>
        <input type="hidden" name="img" value="" id="img">
      </div>
    </div>  
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">详情</label>
    <div class="layui-input-block">
      <textarea class="layui-textarea" id="LAY_demo2" style="display: none">{$info.content}</textarea>
    </div>
  </div>


    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit="" lay-filter="addshop">提交</button>
        </div>
    </div>

</form>



<script src="{$Assets}layui/layui.js?t=1515376178709"></script>
<script>
    layui.use(['form', 'layedit', 'laydate','upload'], function(){
        var form = layui.form
            ,layer = layui.layer
            ,upload = layui.upload
            ,layedit = layui.layedit
            ,laydate = layui.laydate
            ,$ = layui.jquery;

  //
  var uploadInst = upload.render({
    elem: '#test1'
    ,url: 'upload'
    ,before: function(obj){
      //ie8
      obj.preview(function(index, file, result){
        $('#demo1').attr('src', result); //base64
      });
    }
    ,done: function(res){
      //
      if(res.code > 0){
        return layer.msg('上传成功');
      }
      //
     
      $("#img").attr("value",res.data.src);
    }
    ,error: function(){
      //
      var demoText = $('#demoText');
      demoText.html('<span style="color: #FF5722;">1</span> <a class="layui-btn layui-btn-xs demo-reload">2</a>');
      demoText.find('.demo-reload').on('click', function(){
        uploadInst.upload();
      });
    }
  });

        //
        laydate.render({
            elem: '#date'
        });
        laydate.render({
            elem: '#date1'
        });

        //

        layedit.set({
          uploadImage: {
            url: 'editimg' 
            ,type: 'post' 
          }
        });
        var index = layedit.build('LAY_demo2');

        //
        form.verify({
            
        });

          //
        form.on('submit(addshop)', function(data){

          var datas=JSON.stringify(data.field);
          var content=layedit.getContent(index);
          var iframe = parent.layer.getFrameIndex(window.name);


                  $.ajax({
                        type:"POST",
                        url: "{:url('integral/saveshop')}",
                        data:{data:datas,content:content},
                        dataType:"json",

                        success:function(ret_datas){
                            if(ret_datas==1){
                                layer.msg('添加成功!');
                                setTimeout(function(){
                                  parent.layer.close(iframe);
                                  parent.location.reload();
                                },"1000");
                            }else if(ret_datas==99){
                                layer.msg('添加异常');
                            }else{
                                layer.msg(ret_datas);
                            }
                            
                           

                        }
                    });

          return false;
        });






    });
</script>
{include file="public/footer"/}
</body>
</html>
